package com.jinduplan.planmanager.ui.activity.report

import android.content.Intent
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.cxz.kotlin.baselibs.adapter.CustomRecyclerAdapter
import com.cxz.kotlin.baselibs.adapter.ViewHolder
import com.cxz.kotlin.baselibs.base.BaseMvpTitleActivity
import com.cxz.kotlin.baselibs.widget.UniversalItemDecoration
import com.jinduplan.planmanager.R
import com.jinduplan.planmanager.bean.ReportDetailData
import com.jinduplan.planmanager.bean.ReportListData
import com.jinduplan.planmanager.bean.ReportListRecord
import com.jinduplan.planmanager.constant.Constant
import com.jinduplan.planmanager.mvp.contract.LoginRegisterContract
import com.jinduplan.planmanager.mvp.contract.ReportContract
import com.jinduplan.planmanager.mvp.presenter.LoginRegisterPresenter
import com.jinduplan.planmanager.mvp.presenter.ReportPresenter
import com.jinduplan.planmanager.utils.GlideUtil
import com.jinduplan.planmanager.utils.ResUtil
import kotlinx.android.synthetic.main.activity_corrupt_report.*
import kotlinx.android.synthetic.main.activity_rcy_refresh.*
import kotlinx.android.synthetic.main.activity_rcy_refresh.recyclerView
import kotlinx.android.synthetic.main.activity_register.*

class ReportDetailAcitivity:BaseMvpTitleActivity<ReportContract.View, ReportContract.Presenter>(),ReportContract.View {

    val datas  = ArrayList<String>()
    var id = ""

//    override fun initView() {
//        setStatusBarColor(resources.getColor(R.color.transparent_75))
//        setStatusBarIcon(false)
//        super.initView()
//        setBaseTitleColor(android.R.color.white)
//    }

    override fun attachChildLayoutRes(): Int {
        return R.layout.activity_corrupt_report
    }


    override fun createPresenter(): ReportContract.Presenter {
        return ReportPresenter()
    }

    override fun start() {
        setBaseTitle(ResUtil.getS(R.string.corrupt_report))
        intent?.extras?.getString(Constant.REPORT_ID)?.let {
            id = it
        }
        rcyReport.adapter = object :CustomRecyclerAdapter<String>(this,R.layout.item_iv_80,datas){
            override fun convert(holder: ViewHolder, t: String, position: Int) {
                GlideUtil.load(t,holder.getView(R.id.ivPic))
            }

        }
        rcyReport.layoutManager = GridLayoutManager(this,4)
        rcyReport.addItemDecoration(object:UniversalItemDecoration(){
            override fun getItemOffsets(position: Int): Decoration {
                val decoration = ColorDecoration()
                decoration.decorationColor = ResUtil.getC(R.color.transparent)
                decoration.left = ResUtil.getDimen(this@ReportDetailAcitivity,R.dimen.dp_7).toInt()
                decoration.right = ResUtil.getDimen(this@ReportDetailAcitivity,R.dimen.dp_7).toInt()
                decoration.bottom = ResUtil.getDimen(this@ReportDetailAcitivity,R.dimen.dp_18).toInt()
                return decoration
            }
        })
        mPresenter?.getReportDetail(id)

    }

    override fun getDetail(data: ReportDetailData) {
        tvName.setText(data.full_name)
        tvRepoortTime.setText(data.created_at)
        tvStaffTittle.setText(data.position)
        tvReportContent.setText(data.content)
        datas.clear()
        data.images.forEach {
            datas.add("${Constant.BASE_URL}/$it")
        }
        rcyReport.adapter?.notifyDataSetChanged()
    }

    override fun reportSuccess() {
        TODO("Not yet implemented")
    }

    override fun uploadSuccess(url: String) {
        TODO("Not yet implemented")
    }

    override fun refreshReportList(data: ReportListRecord) {
        TODO("Not yet implemented")
    }

    override fun loadReportList(data: ReportListRecord) {
        TODO("Not yet implemented")
    }

}